﻿using Microsoft.AspNetCore.Http;
using System;
using System.Threading.Tasks;

namespace FirstDemo.Common
{
    public class MyMiddleware
    {
        private DateTime _startTime;

        private readonly RequestDelegate _next;

        public MyMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            _startTime = DateTime.Now;
            // Call the next delegate/middleware in the pipeline
            await _next(context);

            await context.Response.WriteAsync("执行耗时：" + (DateTime.Now - _startTime).TotalSeconds.ToString() + "s");
        }
    }
}
